class MyPlugin {
  constructor(options) {
    console.log(options);
    this.options = options
  }
  addTxt(complication, callback) {
    //complication 存储了文件的信息
    var str = '文件列表：\n'
    for (let key in complication.assets) {
      str += '文件名是：' + key + ';大小是：' + complication.assets[key].size() + '\n\n'
    }
    // console.log(complication)
    complication.assets['list.txt'] = {
      source() {
        return str
      },
      size() {
        return str.length
      }
    }
    callback && callback()
  }
  apply(compiler) {
    // console.log(compiler)
    let hooks = compiler.hooks;
    if (hooks) {
      hooks.emit.tap('myplugin',this.addTxt)
    } else {
      compiler.plugin('emit', this.addTxt)
    }

  }
}
module.exports = MyPlugin